package org.example.chapter03.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Bean;
import org.example.chapter03.web.FirstServlet;
import org.example.chapter03.web.SecondServlet;
import org.example.chapter03.web.MyFilter;
import org.example.chapter03.web.MyListener;

<<<<<<< HEAD
import java.util.Collections;
=======
import java.util.Arrays;
>>>>>>> 88114efa11e2c7c122669dd830b6db0b932f4c36


@Configuration
public class WebConfigure
{
//    @Bean("firstServlet")
//    public FirstServlet firstServlet()
//    {
//        return new FirstServlet();
//    }
//
//    @Bean("secondServlet")
//    public SecondServlet secondServlet()
//    {
//        return new SecondServlet();
//    }
//
//    @Bean
//    public MyFilter myFilter()
//    {
//        return new MyFilter();
//    }
//
//    @Bean
//    public MyListener myListener()
//    {
//        return new MyListener();
//    }

    @Bean
    public ServletRegistrationBean firstServlet()
    {
        return new ServletRegistrationBean(new FirstServlet(), "/first");
    }

    @Bean
    public ServletRegistrationBean secondServlet()
    {
        return new ServletRegistrationBean(new SecondServlet(), "/second");
    }

    @Bean
    public FilterRegistrationBean myFilter()
    {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean<>(new MyFilter());
<<<<<<< HEAD
        filterRegistrationBean.setUrlPatterns(Collections.singletonList("/first"));
=======
        filterRegistrationBean.setUrlPatterns(Arrays.asList("/first"));
>>>>>>> 88114efa11e2c7c122669dd830b6db0b932f4c36

        return filterRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean myListener()
    {
        return new ServletListenerRegistrationBean(new MyListener());
    }
}
